import log from '@dfeidao/atom-nodejs/logger/log';
import { IncomingHttpHeaders } from 'http';
import doc_code from '@dfeidao/atom-nodejs/msg/doc-code';
import operate from '@dfeidao/atom-nodejs/db/operate';
import { systemid, productid } from '../../atom/config';

interface Message {
	filter: {
		sub_process_des: string
	}
}

interface IWebResult {
	data: unknown;
	cookie?: {
		[name: string]: string;
	} | null;
	content_type?: string;
	headers?: {
		[key: string]: string;
	};
	attachment?: string;
	redirect?: string;
	status_code?: number;
}
// 表名	hidden_ck_deal_set				
// 标题	隐患检查后续处理选择集				
// 字段名称	字段标题	字段类型	字段长度	是否为空	是否主键
// _id	id	string	50	ⅹ	√
// sub_process_des	后续处理描述	string	50	√	ⅹ
// sub_process_no	后续处理编号	string	50	√	ⅹ

// ,将数据保存到<隐患检查后续处理选择集>表中,

//           "产品ID"=用户登录的"产品ID"

//           "后续处理编号"，依据全局编码生成,

//           "后续处理描述"，=页面"后续处理描述"输入框的值。


export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {
	log('Service begin path:e:\Feidao\kh\src\processing-set\zj-000005\s001,action_id:' + action_id);

	const res = await doc_code(action_id, session_id, systemid, 'BM0014336', '', 1);
	const { exec, insert } = operate(action_id, session_id, systemid);
	insert('hidden_ck_deal_set', {
		sub_process_no: res.result,
		sub_process_des: message.filter.sub_process_des,
		productid
	});
	const r = await exec();
	log('Service end path:e:\Feidao\kh\src\processing-set\zj-000005\s001,action_id:' + action_id);
	return {
		data: r
	};
}
